﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace HRP.Private.Mensagens
{
    public partial class menuMensagens : System.Web.UI.UserControl
    {
        public int numeroMensagenslidas = 0;
        public int numeroMensagensporler = 0;
        public int totalmensagens = 0;
        public int numeroMensagensEnviadas = 0;
        public int active
        {
            get
            {
                if (ViewState["menuMsgActive"] == null)
                {
                    ViewState["menuMsgActive"] = 0;
                }
                return (int)ViewState["menuMsgActive"];
            }
            set {
                ViewState["menuMsgActive"] = value;

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            var msg = Mensagens_BLL.Instance.obterTodasMensagens(Convert.ToInt32(Session["userid"]));
            var msgporler = Mensagens_BLL.Instance.obterMensagens(Convert.ToInt32(Session["userid"]), false);
            var msglida = Mensagens_BLL.Instance.obterMensagens(Convert.ToInt32(Session["userid"]), true);
            var msgenviadas = Mensagens_BLL.Instance.obterMensagensEnviadas(Convert.ToInt32(Session["userid"]));
            int countTo = 0;
            countTo = msg.Count();
            numeroMensagenslidas = msglida.Count();
            numeroMensagensporler = msgporler.Count();
            totalmensagens = countTo;
            numeroMensagensEnviadas = msgenviadas.Count();
            Page.PreRenderComplete += Page_PreRenderComplete;
        }

        void Page_PreRenderComplete(object sender, EventArgs e)
        {
            inboxBT.CssClass = inboxLidas.CssClass = inboxPorLer.CssClass = enviadasBT.CssClass = "list-group-item";
            switch (active)
            {
                case 0: inboxBT.CssClass += " active"; break;
                case 1: inboxLidas.CssClass += " active"; break;
                case 2: inboxPorLer.CssClass += " active"; break;
                case 3: enviadasBT.CssClass += " active"; break;
                default: break;
            }
        }

        protected void inboxBT_Click(object sender, EventArgs e)
        {
            Session.Add("inbox", 0);
            active = 0;
        }

        protected void inboxLidas_Click(object sender, EventArgs e)
        {
            Session.Add("inbox", 1);
            active = 1;
        }

        protected void inboxPorLer_Click(object sender, EventArgs e)
        {
            Session.Add("inbox", 2);
            active = 2;
        }

        protected void enviadas_Click(object sender, EventArgs e)
        {
            Session.Add("inbox", 3);
            active = 3;
        }
    }
}